package com.example.administrator.ttphonehelper.app;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.ttphonehelper.R;
import com.example.administrator.ttphonehelper.base.SimpleBaseAdapter;
import com.example.administrator.ttphonehelper.bean.AppInfoBean;

/**
 * Created by Administrator on 2016/4/18 0018.
 */
public class MyAppAdapter extends SimpleBaseAdapter<AppInfoBean> {
    private static int tag;
    public MyAppAdapter(Context context) {
        super(context);

    }
    public MyAppAdapter(Context context,int tag){
        super(context);
        this.tag =tag;
    }
    public void setTag(int tag){
        this.tag = tag;
    }

    @Override
    public View getItemView(int position, View convertView, ViewGroup parent) {
        //判断加载不同的布局
        switch (tag){
            case 1:
                ViewHolder v1;
                if (convertView==null){
                    v1 = new ViewHolder();
                    convertView = mInflater.inflate(R.layout.app_item1,null);
                    v1.iv_icon = (ImageView) convertView.findViewById(R.id.iv_icon);
                    v1.tv_name = (TextView) convertView.findViewById(R.id.tv_name);

                    convertView.setTag(v1);
                }
                else {
                    v1 = (ViewHolder) convertView.getTag();
                }
                AppInfoBean appInfoBean1 = getItem(position);
                v1.iv_icon.setImageDrawable(appInfoBean1.getIcon());
                v1.tv_name.setText(appInfoBean1.getName());
                break;
            case 2:
                ViewHolder v2;
                if (convertView==null){
                    v2 = new ViewHolder();
                    convertView = mInflater.inflate(R.layout.app_item2,null);
                    v2.iv_icon = (ImageView) convertView.findViewById(R.id.iv_icon);
                    v2.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
                    v2.tv_packageName = (TextView) convertView.findViewById(R.id.tv_package_name);
                    convertView.setTag(v2);
                }
                else {
                    v2 = (ViewHolder) convertView.getTag();

                }
                AppInfoBean appInfoBean2 = getItem(position);
                v2.iv_icon.setImageDrawable(appInfoBean2.getIcon());
                v2.tv_name.setText(appInfoBean2.getName());
                v2.tv_packageName.setText(appInfoBean2.getPackageName());
                break;
        }

        return convertView;
    }
    class ViewHolder{
        public ImageView iv_icon;
        public TextView tv_name;
        public TextView tv_packageName;
    }
}
